﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public static class TransformExtensions
    {
        public static void SetPosition(this Transform transform, float x, float y, float z)
        {
            transform.position = new Vector3(x, y, z);
        }

        public static void SetLocalPosition(this Transform transform, float x, float y, float z)
        {
            transform.localPosition = new Vector3(x, y, z);
        }

        public static void SetLocalScale(this Transform transform, float x, float y, float z)
        {
            transform.localScale = new Vector3(x, y, z);
        }

        public static Transform FindHard(this Transform trans, string path)
        {
            if (path == string.Empty)
            {
                return trans;
            }
            Transform transform = trans;
            string[] array = path.Split(new char[]
            {
                '/'
            });
            foreach (string b in array)
            {
                bool flag = false;
                foreach (object obj in transform)
                {
                    Transform transform2 = (Transform)obj;
                    if (transform2.name == b)
                    {
                        transform = transform2;
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    transform = null;
                    break;
                }
            }
            return transform;
        }
        public static Transform FindByName(this Transform trans, string name)
        {
            if (trans.name == name)
            {
                return trans;
            }
            for (int i = 0; i < trans.childCount; i++)
            {
                Transform child = trans.GetChild(i);
                Transform transform = child.FindByName(name);
                if (transform != null)
                {
                    return transform;
                }
            }
            return null;
        }

        public static Transform FindByName(this Transform trans, string name1, string name2)
        {
            if (trans.name.Equals(name1) || trans.name.Equals(name2))
            {
                return trans;
            }
            for (int i = 0; i < trans.childCount; i++)
            {
                Transform child = trans.GetChild(i);
                Transform transform = child.FindByName(name1, name2);
                if (transform != null)
                {
                    return transform;
                }
            }
            return null;
        }

        public static Transform FindByName(this Transform trans, string name1, string name2, string name3)
        {
            if (trans.name.Equals(name1) || trans.name.Equals(name2) || trans.name.Equals(name3))
            {
                return trans;
            }
            for (int i = 0; i < trans.childCount; i++)
            {
                Transform child = trans.GetChild(i);
                Transform transform = child.FindByName(name1, name2, name3);
                if (transform != null)
                {
                    return transform;
                }
            }
            return null;
        }



    }
}

